export default {
	data() {
		return {
			allowOnloadGetList: true, // 是否允许页面onload生命周期进入后立马执行getlist
			minixPagingListsApi: '', // 接口地址
			pageingListApiMethod: 'post', // 接口请求方法
			pagingListPage: 1, // 分页
			pagingListAllowLoadMore: true, // 允许加载更多
			pagingListLoadedAll: false, // 已加载全部数据
			pagingListNoListData: false, // 没有列表数据,
			isOrder: false, // 订单页面
			listData: [],
			isLoadInit: false, // 初始化数据之后，若无数据再显示无数据图标
		}
	},

	computed: {
		listDataLength() {
			return this.listData.length
		}
	},

	// 下拉刷新
	onPullDownRefresh() {
		uni.stopPullDownRefresh();
		if (this.allowOnloadGetList) {
			this.pagingListToggle(() => {
				// uni.stopPullDownRefresh();
			});
		} else {
			// uni.stopPullDownRefresh();
		}
	},


	onLoad() {
		if (this.allowOnloadGetList) this.pagingListGetLists();
	},

	//上拉加载更多
	onReachBottom() {
		this.pagingListGetLists();
	},

	methods: {
		// 列表切换
		pagingListToggle(fn) {
			this.pagingListPage = 1
			this.pagingListAllowLoadMore = true
			this.pagingListNoListData = false
			this.pagingListLoadedAll = false
			this.pagingListLoadedAll = false
			this.listData = []
			if (fn) this.pagingListGetLists(fn);
			else this.pagingListGetLists();
		},

		// 获取列表数据
		pagingListGetLists(fn) {
			console.log('xxxx', !this.pagingListAllowLoadMore, this.pagingListLoadedAll, this.pagingListNoListData)
			if (!this.pagingListAllowLoadMore || this.pagingListLoadedAll || this.pagingListNoListData) return;
			this.pagingListAllowLoadMore = false;
			let postData = {
				page: this.pagingListPage,
				page_size: global.PAGE_SIZE,
				start_time: this.startDate,
				end_time: this.endDate,
			}
			if (this.orderType == 3) {
				postData.genre = this.genre
			}
			if (this.orderType == 20) {
				
				postData.genre = this.genre
			}
			if (this.orderType == -1) {
				postData.after_sale = this.afterType
			}
			if (this.pagingListPostData) {
				postData = Object.assign({}, postData, this.pagingListPostData());
			}
			this.isShowLoading = true
			this.$api[this.pageingListApiMethod](this.minixPagingListsApi, postData).then(res => {
				console.log(res)
				this.isShowLoading = false
				if (res.data.code == 1) {
					if (this.pagingListBeforeResponseData) res.data.data = this.pagingListBeforeResponseData(
						res);
					let tempLists = res.data.data.data || res.data.data.list,
						totalPage = res.data.data.last_page || 1,
						listData = this.listData;
						
					console.log(listData,"1212121212")
					if (this.pagingListResponseData) tempLists = this.pagingListResponseData(tempLists);
					this.listData.push(...tempLists);
					this.pagingListAllowLoadMore = true;
					if (this.pagingListPage >= totalPage) this.pagingListLoadedAll = true;
					console.log('aaaaa', this.pagingListPage, this.listData.length)
					if (this.pagingListPage == 1 && this.listData.length == 0) this.pagingListNoListData = true;
					this.pagingListPage = this.pagingListPage + 1;
				} else {
					this.pagingListAllowLoadMore = true;
					this.pagingListLoadedAll = true;
					if (this.pagingListPage == 1 && this.listData.length == 0) this.pagingListNoListData = true;
				}
				this.isLoadInit = true;
				this.is_check = false

				if (fn) fn();
			}).catch(err => {
				console.log(err);
				this.isShowLoading = false
				this.pagingListAllowLoadMore = true;
				this.isLoadInit = true;
			})
		}
	}
}
